﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

class Player
{
    public uint m_PlayerID { private set; get; }
    public UserSession m_User { private set; get; }
    public Vector3 m_Pos { private set; get; }
    public float m_RotY { private set; get; }
    public Vector3 m_Target { private set; get; }
    float m_MoveSpeed = 3;

    public bool IsAI()
    {
        return m_User == null; 
    }

    public void Init(UserSession user, uint playerId, Vector3 pos, float rotY)
    {
        m_User = user;
        m_PlayerID = playerId;
        m_Pos = pos;
        m_RotY = rotY;
        SetTarget(m_Pos);
        ServerApp.Instance.AddPlayer(this);
    }

    public void UpdatePos(Vector3 pos, float rotY)
    {
        m_Pos = pos;
        m_RotY = rotY;
    }

    public void SetTarget(Vector3 target)
    {
        m_Target = target;
        LogManager.Error("target=" + target);
    }

    public void TickAI()
    {
        if (!IsAI())
        {
            return;
        }
        if (Vector3.Distance(m_Pos, m_Target) < 0.1f)
        {
            SetTarget(ServerApp.Instance.GetRandomPos(20)); 
            return;
        }
        m_Pos += (m_Target - m_Pos).normalized * m_MoveSpeed * ServerApp.Instance.m_DeltaTime;
    }
}
